
package ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import ui.model.ProfitBean;


/**
 * 当日收益商户适配器
 * Created by chenjian on 19/2/27
 */
public class ProfitShopAdapter extends DelegateAdapter.Adapter<ProfitShopAdapter.ProfitShopVH> {

    private final Context mContext;
    private List<ProfitBean.BackTotalBean> mData;

    public ProfitShopAdapter(Context context) {
        mContext = context;
        mData = new ArrayList<>();
    }

    public void setupData(List<ProfitBean.BackTotalBean> data) {
        mData.clear();
        if (data != null) {
            mData.addAll(data);
        }
        notifyDataSetChanged();
    }

    public List<ProfitBean.BackTotalBean> getData() {
        return mData;
    }
    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public ProfitShopVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProfitShopVH(LayoutInflater.from(mContext).inflate(R.layout.item_profit, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ProfitShopAdapter.ProfitShopVH holder, int position) {
        Spanned strA = Html.fromHtml("商户押金：<font color=#0CA6F0>" + "已激活</font>");
        Spanned strB = Html.fromHtml("返现奖励：<font color=#FF2F2F>" + mData.get(position).getBackReward() + "</font>  元");
        holder.amount.setText(strA);
        holder.income.setText(strB);
        holder.reward.setText("商编：" + mData.get(position).getMerchantNo());
        holder.merchant.setText(mData.get(position).getTransDate());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class ProfitShopVH extends RecyclerView.ViewHolder {
        private TextView amount;
        private TextView income;
        private TextView reward;
        private TextView merchant;

        ProfitShopVH(@NonNull View itemView) {
            super(itemView);
            amount = itemView.findViewById(R.id.item_profit_name);
            income = itemView.findViewById(R.id.item_profit_money);
            reward = itemView.findViewById(R.id.item_profit_type);
            merchant = itemView.findViewById(R.id.item_profit_time);
        }
    }

}
